package polish;

// a stack implemented with a simple linked list

public class Stack <T> implements Stackable <T> {

	
	LinkedList <T> l = new LinkedList <T> ();
	
	public void push (T o) throws StackOverflowException {
		
		// push should put an object on top of the list
			
		l.add(o, 1);
	}

	public Boolean isEmpty() {
	
		return (l.size()==0);
	}

	public T peek() throws StackEmptyException {
		
		if (this.isEmpty()){
			throw new StackEmptyException ("can't peek, nothing there");
		}
		else {
			return l.get(1);
		
		}
	}

	public T pop() throws StackEmptyException {
		
		if (this.isEmpty()){
			throw new StackEmptyException ("can't pop, nothing there");
		}
		else {
			T temp = l.get(1);
			l.remove(1);
			return temp;
		
		}
	
	}
	
	public String toString () {
		return l.toString();
		
		
		
	}

}